package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.OutdoorFitness;
import com.dwxt.sport.business.entity.OutdoorFitnessEquipment;
import com.dwxt.sport.business.service.OutdoorFitnessService;
import com.dwxt.sport.business.vo.outdoorFitness.InsertOrUpdateOutdoorFitnessEquipmentVo;
import com.dwxt.sport.business.vo.outdoorFitness.InsertOrUpdateOutdoorFitnessVo;
import com.dwxt.sport.business.vo.outdoorFitness.SelectOutdoorFitnessVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 室外健身器材 Controller
 *
 * @author Kuang.JiaZhuo
 * @date 2020-07-27 16:03
 */
@RestController
@RequestMapping("/outdoorFitness")
@Api(tags={"室外健身器材相关接口"})
public class OutdoorFitnessController {

    @Resource
    OutdoorFitnessService outdoorFitnessService;

    @ApiOperation(value = "新增室外健身器材", notes = "新增室外健身器材", response = Integer.class)
    @PostMapping("/back/insertOutdoorFitness")
    public BaseResult insertOutdoorFitness(InsertOrUpdateOutdoorFitnessVo insertVo){
        int result = this.outdoorFitnessService.insertOutdoorFitness(insertVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "更新室外健身器材", notes = "更新室外健身器材", response = Integer.class)
    @PostMapping("/back/updateOutdoorFitness")
    public BaseResult updateOutdoorFitness(InsertOrUpdateOutdoorFitnessVo updateVo){
        int result = this.outdoorFitnessService.updateOutdoorFitness(updateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取室外健身器材列表", notes = "按条件查询室外健身器材列表(带分页)", response = OutdoorFitness.class)
    @PostMapping("/back/getOutdoorFitnessByPage")
    public BaseResult getOutdoorFitnessByPage(SelectOutdoorFitnessVo selectVo){
        PageInfo<OutdoorFitness> pageInfo = this.outdoorFitnessService.getOutdoorFitnessByPage(selectVo);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除室外健身器材", notes = "根据ids批量删除室外健身器材", response= Integer.class)
    @PostMapping(value = "/back/deleteOutdoorFitnessByIds")
    public BaseResult deleteOutdoorFitnessByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.outdoorFitnessService.deleteOutdoorFitnessByIds(ids);
        return BaseResult.ok(result);
    }

    /******************************************************************  关联设备  ******************************************************************************/

    @ApiOperation(value = "查询室外健身器材设备列表", notes = "根据室外健身器材的id查询关联设备的列表(带分页)", response= OutdoorFitnessEquipment.class)
    @PostMapping(value = "/back/getOutdoorFitnessEquipmentByPage")
    public BaseResult getOutdoorFitnessEquipmentByPage(@ApiParam(value = "室外健身器材id", required = true) @RequestParam String id,
                                                       @ApiParam(value = "起始页", required = true) @RequestParam Integer pageNum,
                                                       @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize){
        String outdoorFitnessId = id;
        PageInfo<OutdoorFitnessEquipment> pageInfo = this.outdoorFitnessService.getOutdoorFitnessEquipmentByPage(pageNum,pageSize,outdoorFitnessId);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除室外健身器材关联设备", notes = "根据ids批量删除室外健身器材关联的设备", response= Integer.class)
    @PostMapping(value = "/back/deleteOutdoorFitnessEquipmentByIds")
    public BaseResult deleteOutdoorFitnessEquipmentByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.outdoorFitnessService.deleteOutdoorFitnessEquipmentByIds(ids);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "新增室外健身器材的设备关联", notes = "新增室外健身器材关联的设备", response = Integer.class)
    @PostMapping("/back/insertOutdoorFitnessEquipment")
    public BaseResult insertOutdoorFitnessEquipment(InsertOrUpdateOutdoorFitnessEquipmentVo insertVo){
        int result = this.outdoorFitnessService.insertOutdoorFitnessEquipment(insertVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "更新室外健身器材的设备关联", notes = "更新室外健身器材关联的设备", response = Integer.class)
    @PostMapping("/back/updateOutdoorFitnessEquipment")
    public BaseResult updateOutdoorFitnessEquipment(InsertOrUpdateOutdoorFitnessEquipmentVo updateVo){
        int result = this.outdoorFitnessService.updateOutdoorFitnessEquipment(updateVo);
        return BaseResult.ok(result);
    }


}
